﻿package cn.smbms.service.impl;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import cn.smbms.dao.UserMapper;
import cn.smbms.pojo.User;
import cn.smbms.service.UserService;

@Service("userService")
public class UserServiceImpl implements UserService {

	@Resource(name="userMapper")
	private UserMapper userMapper;

	public User login(String userCode, String userPassword) {
		User user = userMapper.getLoginUser(userCode);
		// 匹配密码
		if (null != user) {
			if (!user.getUserPassword().equals(userPassword))
				user = null;
		}
		return user;
	}

	public List<User> getUserList(String queryUserName, int queryUserRole,
			int currentPageNo, int pageSize) {
		return userMapper.getUserList(queryUserName, queryUserRole, currentPageNo,
				pageSize);
	}

	public User selectUserCodeExist(String userCode) {
		return userMapper.getLoginUser(userCode);
	}

	public boolean deleteUserById(Integer delId) {
		return userMapper.deleteUserById(delId) > 0;
	}

	public User getUserById(String id) {
		return userMapper.getUserById(id);
	}

	public boolean modify(User user) {
		return userMapper.modify(user) > 0;
	}

	public boolean updatePwd(int id, String pwd) {
		return userMapper.updatePwd(id, pwd) > 0;
	}

	public int getUserCount(String queryUserName, int queryUserRole) {
		return userMapper.getUserCount(queryUserName, queryUserRole);
	}

	@Override
	public boolean add(User user) {
		return userMapper.add(user)>0;
	}

}
